<!--待办-->
<template>
  <div class="base-content">
    <el-table
      class="filter unsetborder"
      :class="{ 'show-filter': showFilterRow }"
      :data="dataList"
      fit
      highlight-current-row
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55">
        <el-table-column type="selection"></el-table-column>
      </el-table-column>
      <el-table-column align="center" width="50">
        <template #header>
          <div class="filter-icon" title="筛选">
            <SvgIcon
              class-name="filter"
              icon-class="filter"
              @click="filterIconClick"
            />
          </div>
        </template>
        <el-table-column width="50"></el-table-column>
      </el-table-column>
      <el-table-column align="center" label="序号" width="50">
        <el-table-column align="center">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="委托单号">
        <el-table-column prop="orderNum">
          <template #header>
            <el-input
              v-if="showFilterRow"
              v-model="queryForm.orderNum"
              @keyup.enter.native="onQuery"
            ></el-input>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="单位名称">
        <el-table-column prop="customerName">
          <template #header>
            <el-input
              v-if="showFilterRow"
              v-model="queryForm.customerName"
              @keyup.enter.native="onQuery"
            ></el-input>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="样品名称">
        <el-table-column prop="sampleName">
          <template #header>
            <el-input
              v-if="showFilterRow"
              v-model="queryForm.sampleName"
              @keyup.enter.native="onQuery"
            ></el-input>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="检测费用">
        <el-table-column prop="detectionPrice">
          <template slot-scope="scope">
            {{ convertUnit(scope.row.detectionPrice) }}
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="操作">
        <el-table-column width="140">
          <template #header>
            <div v-if="showFilterRow" class="search-operate">
              <el-link type="primary" @click="onQuery">搜索</el-link>
              <el-link @click="cancelForm">清空</el-link>
            </div>
          </template>
          <template slot-scope="scope">
            <div class="base-table-operation">
              <el-link size="mini" type="primary" @click="handleEdit(scope.row)"
                >价格核算</el-link
              >
              <el-link size="mini" type="primary" @click="selUnit(scope.row)"
                >详情</el-link
              >
            </div>
          </template>
        </el-table-column>
      </el-table-column>
    </el-table>
    <EntrustOrderPriceDialog
      ref="EntrustOrderPriceDialog"
      v-model="priceDialogVisible"
      :edit-id.sync="editId"
      :entrust-order-id.sync="entrustOrderId"
      :sample-registration-id.sync="sampleRegistrationId"
      @close="close"
    />
    <!-- 委托单详情 -->
    <EntrustOrderDialog
      v-if="dialogFormVisible"
      ref="EntrustOrderDialog"
      :dialog-form-visible.sync="dialogFormVisible"
      :read-only.sync="readOnly"
      :edit-id.sync="editId"
      @closeDialog="closeDialog"
    />
    <!-- 样品登记详情 -->
    <SampleRegistrationDialog
      v-if="dialogFormSampleRegistrationVisible"
      ref="SampleRegistrationDialog"
      :dialog-form-visible.sync="dialogFormSampleRegistrationVisible"
      :sample-registration-id.sync="sampleRegistrationId"
      :module-enable-entrust="moduleEnableEntrust"
      :read-only.sync="readOnly"
    />
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import EntrustOrderDialog from "../EntrustOrder/EntrustOrderDialog.vue";
import EntrustOrderPriceDialog from "./EntrustOrderPriceDialog.vue";
import SampleRegistrationDialog from "../../../../ModuleSample/views/SampleManage/SampleRegistration/SampleRegistrationDialog.vue";
export default {
  name: "EntrustOrderPriceWaitList",
  components: {
    EntrustOrderDialog,
    EntrustOrderPriceDialog,
    SampleRegistrationDialog,
  },
  props: {
    dataList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      queryForm: {
        orderNum: '',
        customerName: '',
        sampleName: ''
      },
      showFilterRow: false,
      tableDatas: [],
      dialogFormVisible: false,
      dialogFormSampleRegistrationVisible: false,
      readOnly: false,
      editId: "",
      priceDialogVisible: false,
      entrustOrderId: "",
      sampleRegistrationId: "",
    };
  },
  computed: {
    ...mapGetters(["moduleEnableEntrust"]),
  },
  methods: {
    onQuery() {
      this.$emit("updateQueryForm", this.queryForm);
    },

    filterIconClick() {
      this.showFilterRow = !this.showFilterRow;
      !this.showFilterRow && this.cancelForm();
    },
    // 清空筛选条件
    cancelForm() {
      this.queryForm = this.$options.data().queryForm;
      this.$emit("updateQueryForm", this.queryForm);
    },
    handleSelectionChange(val) {
      this.tableDatas = val;
    },
    // 更新列表
    close() {
      this.priceDialogVisible = false;
      this.$emit("getdataList");
      this.$emit("update:isSearch", false);
    },
    // 转化单位分化元
    convertUnit(price) {
      return price / 100;
    },
    handleEdit(rowData) {
      this.entrustOrderId = rowData.entrustOrderId;
      this.sampleRegistrationId = rowData.sampleRegistrationId;
      this.$refs.EntrustOrderPriceDialog.formData = rowData;
      // 判断客户设置了哪个价格核算
      this.editId = rowData.id;
      this.priceDialogVisible = true;
    },
    // 查看
    selUnit(row) {
      this.readOnly = true;
      this.editId = row.entrustOrderId;
      this.sampleRegistrationId = row.sampleRegistrationId;
      if (
        row.entrustOrderId !== 0 &&
        row.entrustOrderId !== "" &&
        row.entrustOrderId !== "0"
      ) {
        this.dialogFormVisible = true;
      } else if (
        row.sampleRegistrationId !== 0 &&
        row.sampleRegistrationId !== "" &&
        row.sampleRegistrationId !== "0"
      ) {
        this.dialogFormSampleRegistrationVisible = true;
      }
    },
    // 关闭弹框清空id
    closeDialog() {
      this.editId = "";
      this.readOnly = false;
    },
    closePriceDialog() {
      this.editId = "";
      this.priceDialogVisible = false;
      this.readOnly = false;
    },
  },
};
</script>
